<?php

/**
 * @author VoXuanHoan
 * @version $Id$
 */
class Admin_CommentController extends ExtLb_Controller_Action
{
	private $commentTbl;

    public function init()
    {
    	$this->loadCss('admin', 'comment', FOLDER_ROOT_NAME);
    	$this->loadLayout('admin', 'layout');
    	
        $this->commentTbl	= new Admin_Model_Comments();
    }

    public function indexAction()
    {
    	if(isset($_GET['search_box_sumit']) && !empty($_GET['search_box_text'])){
    		$selectComment = $this->commentTbl->selectComment("chuDe like '%".$_GET['search_box_text']."%'");
    	}else{
    		$selectComment = $this->commentTbl->selectComment();
    	}
    	
    	$paginatorComments = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($selectComment));
    	$paginatorComments->setItemCountPerPage(20)
    					->setPageRange(3)
    					->setCurrentPageNumber($this->_getParam('page',1));
    					
    	$this->view->paginatorComments = $paginatorComments;
    	
    	//FORWARD TO DELETE ACTION
    	if(isset($_GET['cmdDel']) && !empty($_GET['comment-check'])){
    		$this->_forward('delete','comment','admin');
    	}
    }
    
    public function detailAction(){
    	if(isset($_GET['yk']) && !empty($_GET['yk'])){
    		$comment = $this->commentTbl->selectComment("yKienId =".$_GET['yk'])
    									->query()
    									->fetchAll();
    		
    									print_r($comment);
    		$this->view->comment = $comment;
    	}else{
    		$this->_redirect('/admin/comment/');
    	}
    }
    
    public function deleteAction(){
    	if(isset($_GET['cmdDel']) && !empty($_GET['comment-check'])){
    		$arr = $_GET['comment-check'];
    		for ($i = 0; $i < count($arr); $i++) {
    			$this->commentTbl->deleteComment($arr[$i]);	
    		}
    	}
    	$this->_redirect('/admin/comment/');
    }


}

